﻿using System;

namespace StoCombatLogHUD.Toolkit.ExtensionMethods
{
	/// <summary>
	/// Usefull EventHandler extensions.
	/// </summary>
	public static class EventHandlerExtensions
	{
		/// <summary>
		/// Invokes an EventHandler or does nothing if it's null.
		/// </summary>
		/// <param name="eventHandler">The event handler.</param>
		/// <param name="sender">The sender.</param>
		public static void InvokeNullSafe(this EventHandler eventHandler, object sender)
		{
			if (eventHandler != null)
				eventHandler.Invoke(sender, EventArgs.Empty);
		}

		/// <summary>
		/// Invokes an EventHandler or does nothing if it's null.
		/// </summary>
		/// <typeparam name="TEventArgs">The type of the event args.</typeparam>
		/// <param name="eventHandler">The event handler.</param>
		/// <param name="sender">The sender.</param>
		/// <param name="eventArgs">The event args.</param>
		public static void InvokeNullSafe<TEventArgs>(this EventHandler<TEventArgs> eventHandler, object sender, TEventArgs eventArgs)
			where TEventArgs : EventArgs
		{
			if (eventHandler != null)
				eventHandler.Invoke(sender, eventArgs);
		}
	}
}
